/**
 * 用两个栈实现队列的方法
 */

import java.util.Queue;
import java.util.Stack;

class MyQueue2 {

    private Stack<Integer> s1;
    private Stack<Integer> s2;

    public MyQueue2() {
        s1 = new Stack<>();
        s2 = new Stack<>();
    }

    public void push(int x) {
        s1.push(x);
    }


    public int pop() {
        if(!s2.empty()) {
            return s2.pop();
        } else if(!s1.empty()) {
            int size = s1.size();
            for (int i = 0; i < size; i++) {
                s2.push(s1.pop());
            }
            return s2.pop();
        }
        return -1;
    }

    public int peek() {
        if(!s2.empty()) {
            return s2.peek();
        } else if(!s1.empty()) {
            int size = s1.size();
            for (int i = 0; i < size; i++) {
                s2.push(s1.pop());
            }
            return s2.peek();
        }
        return -1;
    }

    //如果两个栈 都是空的 那么队列就是空的
    public boolean empty() {
        return s1.empty() && s2.empty();
    }

}